<?
ob_start();
session_start();
include("../conf/config.php");
include("../conf/database.php");
include("../conf/tools.php");

$curTime=getIndianDateTime();
$memberId=$_GET["mid"];
$groupId=$_GET["gid"];
$mode=$_GET["mode"]; 


if($_GET["mode"]=="del_member"){

exec_qry("delete from bkitc_email_group_map where  fk_group_id=".$groupId." and fk_member_id=".$memberId);

header("location:edit_email.php?mode=edit&gid=".$groupId);
exit;
}

if($_GET["mode"]=="del"){

exec_qry("delete from bkitc_email_group_map where  fk_group_id=".$groupId);
exec_qry("delete from bkitc_email_group where  group_id=".$groupId);

header("location:email_list.php");
exit;
}

foreach($_POST as $key => $value) { $arr_data[$key]=$value;}


foreach($arr_data as $key => $value) { $arr_data[$key]=addslashes($value);}

$arr_data["rec_status"]=1;
if($groupId>0)
{

update_qry("bkitc_email_group",$arr_data,"group_id=".$groupId);
qry_data("update bkitc_email_group set last_updated='".$curTime."' where group_id=".$groupId);


}
else
{

	$groupId=insert_qry("bkitc_email_group",$arr_data);
	qry_data("update bkitc_email_group set last_updated='".$curTime."' where group_id=".$groupId);

}

$memberList=$_POST["group_member"];

exec_qry("delete from bkitc_email_group_map where  group_id=".$groupId);
foreach($memberList as $member){

	$arr_data_info["fk_member_id"]=$member;
	$arr_data_info["fk_group_id"]=$groupId;
	insert_qry("bkitc_email_group_map",$arr_data_info);

} 


header("location:edit_email.php?mode=edit&gid=".$groupId);
?>



